package com.shopping.controller.back;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shopping.commons.controller.BaseController;
import com.shopping.commons.response.DataGradResp;
import com.shopping.commons.response.MessageResp;
import com.shopping.model.Commodity;
import com.shopping.param.CommodityParam;
import com.shopping.response.CommodityResp;
import com.shopping.service.ICommodityService;

/**
 * 商品的   Conroller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("back/commodity") 
public class CommodityController extends BaseController{

	@Autowired
	private ICommodityService commodityService;
	
	/**
	 * 增加某个商品
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("insert")
	@ResponseBody  ///这个是吧MessageResp转成  json 的注解   普遍就是   对应  ajax 的请求    
	public MessageResp insert(HttpServletRequest request,Commodity param){

		return commodityService.insert(param);
	}
	
	/**
	 * 查询 商品
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("select")
	@ResponseBody  
	public DataGradResp<CommodityResp> select(HttpServletRequest request,CommodityParam param){
		return commodityService.select(param);
	}
	
	/**
	 * 删除商品   
	 * @param request
	 * @param param
	 * @return
	 */
	/*resetful 接口规范  接口编码的风格*/
	@RequestMapping(value="{id}",method=RequestMethod.DELETE)
	@ResponseBody 
	public MessageResp delete(HttpServletRequest request,@PathVariable("id") Integer id){
		return commodityService.delete(id);
	}
	
	@RequestMapping("update")
	@ResponseBody 
	public MessageResp update(HttpServletRequest request,Commodity param){
		return commodityService.update(param);
	}

}
